package com.oocl.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import com.oocl.commandParser.CommandParser;
import com.oocl.commandProces.CommandProcess;

public class Controller {
	
	InputStream in;
	OutputStream out;
	BufferedReader reader;
	CommandParser parser;
	CommandProcess process;
	
	public Controller(InputStream in, OutputStream out){
		this.in = in;
		this.out = out;
		reader = new BufferedReader(new InputStreamReader(in));
		parser = new CommandParser();
		process = new CommandProcess(in, out);
	}
	
	public void process() throws IOException{
		String command = reader.readLine();
		String[] result = parser.parse(command);
		if(result.length == 1){
			process.view("D:\\scpSSh\\");
		}else if(result.length == 2){
			process.remove(result[1]);
		}else if(result.length == 3){
			process.upload(result[2]);
		}else{
			out.write("Command error!".getBytes());
		}
		
	}
	
}
